home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / DRAWSTAT.PAK / DRAWSTAT.CPP next >
C/C++ Source or Header  |  1997-05-06  |  4KB  |  163 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1995 by Borland International, All Rights Reserved
  4. //----------------------------------------------------------------------------
  5. #include <owl/pch.h>
  6. #include <owl/applicat.h>
  7. #include <owl/framewin.h>
  8. #include <owl/uihelper.h>
  9. #include <owl/listbox.h>
  10. #include <owl/gdiobjec.h>
  11. #include <stdio.h>
  12. #include "drawstat.rh"
  13.  
  14. class TTestWindow : public TDialog {
  15.   public:
  16.     TTestWindow();
  17.  
  18.   protected:
  19.     void    Paint(TDC& dc, bool erase, TRect& rect);
  20.     void    SetupWindow();
  21.     LRESULT EvCommand(uint id, HWND hWndCtl, uint notifyCode);
  22.  
  23.     void    PaintSample(TDC& dc);
  24.     void    Update();
  25.  
  26.     uint  Type;
  27.     uint  State;
  28.     TRect SampleRect;
  29.     TBitmap SampleBmp;
  30.     TIcon SampleIcn;
  31.  
  32.   DECLARE_RESPONSE_TABLE(TTestWindow);
  33. };
  34.  
  35. DEFINE_RESPONSE_TABLE1(TTestWindow, TWindow)
  36.   EV_WM_WININICHANGE,
  37. END_RESPONSE_TABLE;
  38.  
  39.  
  40. TTestWindow::TTestWindow()
  41. :
  42.   TDialog(0, IDD_DRAWSTATE, 0),
  43.   SampleBmp(*GetModule(), IDB_SAMPLE),
  44.   SampleIcn(*GetModule(), TResId(IDI_SAMPLE))
  45. {
  46.   SetBkgndColor(TColor::Sys3dFace);
  47. }
  48.  
  49. //
  50. //
  51. //
  52. void
  53. TTestWindow::SetupWindow()
  54. {
  55.   TDialog::SetupWindow();
  56.  
  57.   SendDlgItemMessage( IDC_BITMAP, BM_SETCHECK, 1, 0 );
  58.  
  59.   ::GetWindowRect(GetDlgItem(IDC_SAMPLE), &SampleRect);
  60.   ScreenToClient(SampleRect.TopLeft());
  61.   ScreenToClient(SampleRect.BottomRight());
  62.   ::DestroyWindow(GetDlgItem(IDC_SAMPLE));
  63.   Update();
  64. }
  65.  
  66.  
  67. void
  68. TTestWindow::PaintSample(TDC& dc)
  69. {
  70.   dc.SelectObject(TBrush(TColor::Sys3dFace));
  71.   dc.PatBlt(SampleRect.InflatedBy(10,10), PATCOPY);
  72.  
  73.   dc.SetBkColor(TColor::Sys3dHilight);
  74.   dc.SetTextColor(TColor::Sys3dFace);
  75.  
  76.   LPARAM lp = 0;
  77.   switch (Type) {
  78.     case DST_BITMAP:
  79.       lp = LPARAM((HBITMAP)SampleBmp);
  80.       break;
  81.     case DST_ICON:
  82.       lp = LPARAM((HICON)SampleIcn);
  83.       break;
  84.     case DST_TEXT:
  85.       lp = LPARAM("PushMe");
  86.       break;
  87.     case DST_PREFIXTEXT:
  88.       lp = LPARAM("Click&Me");
  89.       break;
  90.   }
  91.  
  92.   TUIFace::Draw(dc, TBrush(TColor::Sys3dShadow), lp, 0,
  93.             SampleRect.left, SampleRect.top,
  94.             SampleRect.Width(), SampleRect.Height(), Type | State);
  95. }
  96.  
  97. //
  98. // Paint some UI style thingies
  99. //
  100. void
  101. TTestWindow::Paint(TDC& dc, bool, TRect&)
  102. {
  103.   PaintSample(dc);
  104. }
  105.  
  106. LRESULT
  107. TTestWindow::EvCommand(uint id, HWND hWndCtl, uint notifyCode)
  108. {
  109.   if (!hWndCtl)
  110.     return TDialog::EvCommand(id, hWndCtl, notifyCode);
  111.  
  112.   Update();
  113.   Invalidate();
  114.   UpdateWindow();
  115.  
  116.   return true;
  117. }
  118.  
  119. void
  120. TTestWindow::Update()
  121. {
  122.   static int typeBit[] = {
  123.     DST_BITMAP,
  124.     DST_ICON,
  125.     DST_PREFIXTEXT,
  126.     DST_TEXT,
  127.   };
  128.   Type = 0;
  129.   int i;
  130.   for (i = 0; i < COUNTOF(typeBit); i++)
  131.     if (IsDlgButtonChecked(IDC_BITMAP + i))
  132.       Type |= typeBit[i];
  133.  
  134.   static int stateBit[] = {
  135.     DSS_NORMAL,
  136.     DSS_UNION,
  137.     DSS_DISABLED,
  138.     DSS_MONO,
  139.     DSS_RIGHT,
  140.   };
  141.   State = 0;
  142.   for (i = 0; i < COUNTOF(stateBit); i++)
  143.     if (IsDlgButtonChecked(IDC_NORMAL + i))
  144.       State |= stateBit[i];
  145. }
  146.  
  147. //----------------------------------------------------------------------------
  148.  
  149. class TTestApp : public TApplication {
  150.   public:
  151.     TTestApp() : TApplication() {}
  152.     void InitMainWindow() {
  153.       MainWindow = new TFrameWindow(0, "DrawState", new TTestWindow, true);
  154.       MainWindow->Attr.Style &= ~WS_THICKFRAME;
  155.     }
  156. };
  157.  
  158. int
  159. OwlMain(int /*argc*/, char* /*argv*/ [])
  160. {
  161.   return TTestApp().Run();
  162. }
  163.